package com.whnk.web.controller.workflow;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.util.ShiroUtils;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.workflow.domain.Leave;
import com.whnk.workflow.service.ILeaveAprService;
import com.whnk.workflow.service.ILeaveService;

/**
 * 请假审批 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-04-16
 */
@Controller
@RequestMapping("/workflow/leaveApr")
public class LeaveAprController extends BaseController
{
    private String prefix = "workflow/leaveApr";
	
	@Autowired
	private ILeaveService leaveService;
	@Autowired
	private ILeaveAprService leaveAprService;
	
	@RequiresPermissions("workflow:leaveApr:view")
	@GetMapping()
	public String leaveApr()
	{
	    return prefix + "/leaveApr";
	}
	
	/**
	 * 查询请假审批列表（未归档）
	 */
	@RequiresPermissions("workflow:leaveApr:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Leave leave)
	{
		startPage();
		leave.setAprLoginName(ShiroUtils.getLoginName());
        List<Leave> list = leaveService.selectLeaveListUnfinished(leave);
		return getDataTable(list);
	}
	
	/**
	 * 审批
	 */
	@GetMapping("/edit/{businessKey}")
	public String edit(@PathVariable("businessKey") String businessKey, ModelMap mmap)
	{
		Leave leave = leaveService.selectLeaveById(businessKey);
		mmap.put("leave", leave);
	    return prefix + "/apr";
	}
	
	/**
	 * 保存审批
	 */
	@RequiresPermissions("workflow:leaveApr:edit")
	@Log(title = "请假审批", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(String businessKey, String opinion, String approveReason)
	{
		return toAjax(leaveAprService.apr(businessKey, opinion, approveReason));
	}
}
